﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Rizmar.RizmarDataSetTableAdapters;

namespace Rizmar
{
    public partial class Desconto : UserControl
    {
      
        internal List<Desconto> descontos;
        ClienteForm parent;
        public Desconto()
        {
            descontos = new List<Desconto>();

            InitializeComponent();
        }

        public Desconto(ClienteForm form)
        {
            descontos = new List<Desconto>();
            parent = form;
            InitializeComponent();
        }

        public bool Completo()
        {           
            if (valorDescontoTextBox.Text == string.Empty)
                return false;
            
            return true; 
        }

        private void excluirDesconto_Click_1(object sender, EventArgs e)
        {
            parent.salvarDescontoNovo();
            if (parent.n_descontos > 1)
            {
            DialogResult dlgResult = MessageBox.Show("Tem certeza que deseja deletar este desconto?", "Deletar Desconto", MessageBoxButtons.OKCancel);
            if (dlgResult == DialogResult.OK)
            {
                DescontoTableAdapter dta = new DescontoTableAdapter();
                RizmarDataSet.DescontoDataTable ddt = new RizmarDataSet.DescontoDataTable();
                //MessageBox.Show(Convert.ToString(parent.descontos.Count));
                parent.panelDesconto.Controls.Remove(parent.panelDesconto.Controls[Convert.ToInt32(idDescLabel.Text) - 1]);
                parent.descontos.RemoveAt(Convert.ToInt32(idDescLabel.Text) - 1);
                dta.DeleteDescontoEspecifico(Convert.ToInt32(parent.idTextBox.Text), Convert.ToInt32(this.idDescLabel.Text));
                parent.n_descontos--;
                parent.limpaForm();
                parent.atualizaDescontos();
            }          
            }
        }
    }
}
